<cfcomponent displayname="issuesGateway" output="false">
	<cffunction name="init" access="public" output="false" returntype="trac_fu.model.issues.issuesGateway">
		<cfargument name="dsn" type="string" required="true" />
		<cfset variables.dsn = arguments.dsn />
		<cfreturn this />
	</cffunction>
	
	<cffunction name="getByAttributes" access="public" output="false" returntype="query">
		<cfargument name="id" type="string" required="false" />
		<cfargument name="projectidfk" type="string" required="false" />
		<cfargument name="created" type="date" required="false" />
		<cfargument name="updated" type="date" required="false" />
		<cfargument name="name" type="string" required="false" />
		<cfargument name="useridfk" type="string" required="false" />
		<cfargument name="creatoridfk" type="string" required="false" />
		<cfargument name="description" type="string" required="false" />
		<cfargument name="history" type="string" required="false" />
		<cfargument name="isbug" type="boolean" required="false" />
		<cfargument name="locusidfk" type="string" required="false" />
		<cfargument name="severityidfk" type="string" required="false" />
		<cfargument name="statusidfk" type="string" required="false" />
		<cfargument name="relatedurl" type="string" required="false" />
		<cfargument name="attachment" type="string" required="false" />
		<cfargument name="publicid" type="numeric" required="false" />
		<cfargument name="duedate" type="date" required="false" />
		<cfargument name="orderby" type="string" required="false" />
		
		<cfset var qList = "" />		
		<cfquery name="qList" datasource="#variables.dsn#">
			SELECT
				id,
				projectidfk,
				created,
				updated,
				name,
				useridfk,
				creatoridfk,
				description,
				history,
				isbug,
				locusidfk,
				severityidfk,
				statusidfk,
				relatedurl,
				attachment,
				publicid,
				duedate
			FROM	issues
			WHERE	0=0
		
		<cfif structKeyExists(arguments,"id") and len(arguments.id)>
			AND	id = <cfqueryparam value="#arguments.id#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"projectidfk") and len(arguments.projectidfk)>
			AND	projectidfk = <cfqueryparam value="#arguments.projectidfk#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"created") and len(arguments.created)>
			AND	created = <cfqueryparam value="#arguments.created#" CFSQLType="cf_sql_date" />
		</cfif>
		<cfif structKeyExists(arguments,"updated") and len(arguments.updated)>
			AND	updated = <cfqueryparam value="#arguments.updated#" CFSQLType="cf_sql_date" />
		</cfif>
		<cfif structKeyExists(arguments,"name") and len(arguments.name)>
			AND	name = <cfqueryparam value="#arguments.name#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"useridfk") and len(arguments.useridfk)>
			AND	useridfk = <cfqueryparam value="#arguments.useridfk#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"creatoridfk") and len(arguments.creatoridfk)>
			AND	creatoridfk = <cfqueryparam value="#arguments.creatoridfk#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"description") and len(arguments.description)>
			AND	description = <cfqueryparam value="#arguments.description#" CFSQLType="cf_sql_longvarchar" />
		</cfif>
		<cfif structKeyExists(arguments,"history") and len(arguments.history)>
			AND	history = <cfqueryparam value="#arguments.history#" CFSQLType="cf_sql_longvarchar" />
		</cfif>
		<cfif structKeyExists(arguments,"isbug") and len(arguments.isbug)>
			AND	isbug = <cfqueryparam value="#arguments.isbug#" CFSQLType="cf_sql_bit" />
		</cfif>
		<cfif structKeyExists(arguments,"locusidfk") and len(arguments.locusidfk)>
			AND	locusidfk = <cfqueryparam value="#arguments.locusidfk#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"severityidfk") and len(arguments.severityidfk)>
			AND	severityidfk = <cfqueryparam value="#arguments.severityidfk#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"statusidfk") and len(arguments.statusidfk)>
			AND	statusidfk = <cfqueryparam value="#arguments.statusidfk#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"relatedurl") and len(arguments.relatedurl)>
			AND	relatedurl = <cfqueryparam value="#arguments.relatedurl#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"attachment") and len(arguments.attachment)>
			AND	attachment = <cfqueryparam value="#arguments.attachment#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"publicid") and len(arguments.publicid)>
			AND	publicid = <cfqueryparam value="#arguments.publicid#" CFSQLType="cf_sql_integer" />
		</cfif>
		<cfif structKeyExists(arguments,"duedate") and len(arguments.duedate)>
			AND	duedate = <cfqueryparam value="#arguments.duedate#" CFSQLType="cf_sql_date" />
		</cfif>
		<cfif structKeyExists(arguments, "orderby") and len(arguments.orderBy)>
			ORDER BY #arguments.orderby#
		</cfif>
		</cfquery>
		
		<cfreturn qList />
	</cffunction>

</cfcomponent>